//分发糖果  力扣135
class Solution {
public:
	int candy(vector<int>& ratings) {
		vector<int> ans(ratings.size(),1);
		//从左到右遍历，右边比左边的大
		for(int i = 1; i < ratings.size(); i++)
			if(ratings[i] > ratings[i-1]) ans[i] = ans[i-1]+1;
		//从右到左遍历，左边要比右边的大
		for(int i = ratings.size() - 2; i >= 0; i--)
			if(ratings[i] > ratings[i+1]) ans[i] = max(ans[i+1]+1,ans[i]);
		int result = 0;
		for(int i = 0; i < ratings.size(); i++)
			result += ans[i];
		return result;
	}
};
